package org.freespace.controller;


import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.freespace.document.dao.MemberReadHistoryDao;
import org.freespace.document.MemberReadHistory;
import org.freespace.entity.PmsProduct;
import org.freespace.service.IPmsProductService;
import org.freespace.service.RedisService;
import org.freespace.utils.response.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 商品信息 前端控制器
 * </p>
 *
 * @author astupidcoder
 * @since 2021-08-21
 */
//@RestController = @Controller + @ResponseBody??
@Slf4j
@RequestMapping("/p")
@Controller
public class PmsProductController {
    @Autowired
    private IPmsProductService iPmsProductService;

    @Autowired
    private RedisService redisService;

    @Autowired
    private MemberReadHistoryDao memberReadHistoryDao;


    @GetMapping("/g")
    @ResponseBody
    public PmsProduct getUser() {
        MemberReadHistory mrh = new MemberReadHistory();
        mrh.setId("1");
        mrh.setProductName("蘋果");
        memberReadHistoryDao.saveDemo(mrh);
        log.info("======redis:{}", redisService.get("key"));
        return iPmsProductService.getById(1);
    }

    @PostMapping("/test")
    @ResponseBody
    public CommonResult getUser(@RequestBody Map<String, String> jobReq) {
       log.info("111111111111111:{}", jobReq);
       List<JSONObject> list = new ArrayList<>();

        for (int i = 0; i < 10; i++) {
            JSONObject s = new JSONObject();
            s.put("id", "xxx");
            s.put("name", "xxx");
            s.put("price", "xxx");
            s.put("xx", "xxx");
            list.add(s);
        }



        return CommonResult.success(list);
    }


}
